/*
 * $Id: File.h,v 1.4 2006-02-07 05:53:45 bacon Exp $
 */
#ifndef _XPP_BAS_FILE_CLASS_
#define _XPP_BAS_FILE_CLASS_

#include <xpp/Uncopyable.h>
#include <xp/bas/sysapi.h>

namespace xpp
{
	namespace bas
	{

		//
		// TODO: make it copyable by using dup or dup2 
		//       in the copy constructor and the operator=
		//
		class File: public Uncopyable
		{
		public:
			File (xp_hnd_t handle = XP_HND_INVALID);
		
			int errorCode () const 
			{
				return error_code;
			}
		
			xp_hnd_t handle () const 
			{
				return this->file_handle;
			}

			void setHandle (xp_hnd_t hnd) 
			{
				this->file_handle = hnd;
			}

			int isOpen ()  const
			{
				return this->file_handle != XP_HND_INVALID;
			}
		
			int open (const xp_char_t* name, int flags);
			int open (const xp_char_t* name, int flags, xp_mode_t mode);
			int opentmp (xp_char_t* buf, bool unlink_after_creation = false);
			int close ();
			xp_ssize_t read  (void* buf, xp_size_t count);
			xp_ssize_t write (const void* buf, xp_size_t count);

			xp_off_t seek (xp_off_t offset, int origin);

			int stat (xp_stat_t* buf);
			int truncate (xp_off_t sz);
			int chmod (xp_mode_t mode);
		
		protected:
			xp_hnd_t file_handle;
			int error_code;
		};
		
	}
}
#endif
		
